package com.zmyuan.demo.netty.combine.client;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.handler.codec.http.DefaultFullHttpResponse;
import io.netty.handler.codec.http.DefaultHttpResponse;
import io.netty.handler.codec.http.DefaultLastHttpContent;

import java.nio.charset.Charset;

/**
 * Created by zdb on 2017/2/15.
 */
public class CombineClientHandler extends ChannelInboundHandlerAdapter {

    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {

        if(msg instanceof DefaultHttpResponse) {
            DefaultHttpResponse response = (DefaultHttpResponse)msg;

            String rep = response.status().toString();
            System.out.println(rep);
        } else if(msg instanceof DefaultFullHttpResponse) {
            DefaultFullHttpResponse response = (DefaultFullHttpResponse)msg;

            String rep = response.content().toString(Charset.forName("UTF-8"));
            System.out.println(rep);
        } else if(msg instanceof DefaultFullHttpResponse) {
            DefaultFullHttpResponse response = (DefaultFullHttpResponse)msg;
            String rep = response.content().toString(Charset.forName("UTF-8"));
            System.out.println(rep);
        } else if(msg instanceof DefaultLastHttpContent) {
            DefaultLastHttpContent response = (DefaultLastHttpContent)msg;
            String rep = response.content().toString(Charset.forName("UTF-8"));
            System.out.println(rep);
        }
        else {
            System.out.println("没有该类型...");

        }

    }
}
